Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows @inacessible in subgraphs #1638

Merged
merged 3 commits into from
Mar 25, 2022

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Mar 24, 2022

Currently, this PR is built on top of #1637, so it would make sense to review that latter PR first and only the last commit is truly relevant to this PR.

@netlify
Copy link

netlify bot commented Mar 24, 2022

👷 Deploy request for apollo-federation-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7257cd2

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 24, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.


const REFERENCED_INACCESSIBLE = makeCodeDefinition(
'REFERENCED_INACCESSIBLE',
'An element is marked as @inaccessible but is referenced by a non-inacessible elemnent (at least in post-merging of the subgraphs)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"non-inacessible" -> "non-inaccessible"
"elemnent" -> "element"

Also I don't love the "at least in post-merging", not sure exactly how I'd change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed about the "post-merging" parts that it's not super clear. I ended up removing it because 1) I wasn't sure either how to say that better and 2) that error can also be thrown by non-merge related calls to toAPISchema so it's probably not worth trying to be overly precise after all.

@@ -1402,6 +1406,51 @@ export class Schema {
specifiedByDirective(schema: Schema): DirectiveDefinition<{url: string}> {
return this.getBuiltInDirective(schema, 'specifiedBy');
}

elementByCoordinate(coordinate: string): NamedSchemaElement<any, any, any> | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment that links to a spec that defines what a syntactically correct coordinate is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linked to graphql/graphql-spec#794. Not sure there is better place to link yet since it's one of those graphQL spec changes that seems pretty much finalised but not quite published yet.

const argName = argStartIdx < 0 ? undefined : coordinate.slice(argStartIdx + 1, coordinate.length - 2);
const splittedStart = start.split('.');
const typeOrDirectiveName = splittedStart[0];
const fieldOrEnumName = splittedStart.length > 1 ? splittedStart[1] : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splittedStart.length > 1 ? splittedStart[1] : undefined;

is equivalent to

splittedStart[1]

since accessing an invalid index in an array will return undefined

@@ -862,6 +868,10 @@ export function setSchemaAsFed2Subgraph(schema: Schema) {
completeSubgraphSchema(schema);
}

// This is the full @link declaration as added by `asFed2SubgraphDocument`. It's here primarily for uses by tests that print and match
// subgraph schema to avoid having to update 20+ tests every time we use a new directive or the order of import changes ...
export const FEDERATION2_LINK_WTH_FULL_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible"])';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done programmatically by manipulating allFederationDirectives rather than hardcoding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, but I actually didn't do it intentionally. The main use of this is for test assertions and I'd hate to have some syntax issue go unnoticed because we made the same programming error in the code tested and the code used to test it. In other words, I think there is value in having this laid out in plain-text at least once so we can eyeball any issue, and don't think it's a big deal to have to have to update that one place every so often, it's having to update 20 places that was getting on my nerves.

But I reckon that this is caution on my part that borders on paranoia, so let me know if you're not convinced and would prefer generating it as I don't feel strongly at all.

const builder = new GraphBuilderFromSchema(
name,
schema,
supergraphSchema ? { apiSchema: supergraphSchema?.toAPISchema(), isFed1: isFed1Supergraph(supergraphSchema) } : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? in supergraphSchema?.toAPISchema() is unnecessary

: [];
const element = e.extensions['inaccessible_element'];
// We only point to subgraphs where the element is marked inaccesssible, as other subgraph are not relevant.
const elementNodes = element && typeof element === 'string'
Copy link
Contributor

@clenfest clenfest Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the indentation of this one pretty tough. Might be more readable as:

const elementNodes = element && typeof element === 'string'
        ? sourceASTs(
            ...this.subgraphsSchema
              .map((schema) => schema.elementByCoordinate(element))
              .filter((elt) => elt?.hasAppliedDirective(federationMetadata(elt.schema())!.inaccessibleDirective()))
            )
        : [];

@pcmanus
Copy link
Contributor Author

pcmanus commented Mar 25, 2022

Side-note: I rebased on main since #1637 has now be merged.

@pcmanus pcmanus closed this Mar 25, 2022
@pcmanus pcmanus reopened this Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants